using UnityEngine;

public class PlayerState_完美闪避 : PlayerStateBase
{
	private float _EnterDrag;

	public override void OnEnter()
	{
		_EnterDrag = _Mono._Rb2D.drag;
		_Mono._Rb2D.drag = 0f;
		_Mono._Rb2D.velocity = Vector2.zero;
		Object.Instantiate(_Mono._GO_完美闪避残影Prefab, _Mono.transform.position, Quaternion.identity);
		_Mono._Ani.Play("完美闪避");
		if (_Mono._Dir == Vector2.zero)
		{
			_Mono._Rb2D.velocity = new Vector2((_Mono._朝向右边 ? 1 : (-1)) * 13, 0f);
		}
		else
		{
			_Mono._Rb2D.velocity = _Mono._Dir * 13f;
		}
		_Mono.F_玩家转向(0f - _Mono._Rb2D.velocity.x);
		_Mono._可以受击 = false;
		_Timer = 0.3f;
		_NextState = StateType_Player.正常移动;
		MonoSingleton<AudioManager>.Instance.F_Play_SFX(((double)Random.value < 0.5) ? _Mono._AudioC_完美闪避1 : _Mono._AudioC_完美闪避2);
	}

	public override void OnExit()
	{
		_Mono._Rb2D.drag = _EnterDrag;
		_Mono._可以受击 = true;
	}

	public override void OnUpdate()
	{
		base.OnUpdate();
		if (Input.GetKeyDown(KeyCode.I))
		{
			F_跳跃();
		}
		else if (Input.GetKeyDown(KeyCode.J))
		{
			F_轻攻击();
		}
		else if (Input.GetKeyDown(KeyCode.L))
		{
			F_翻滚();
		}
		else if (Input.GetKeyDown(KeyCode.K))
		{
			F_重攻击Down();
		}
		else if (Input.GetKeyDown(KeyCode.O))
		{
			F_棍花Down();
		}
		else if (Input.GetKeyDown(KeyCode.R))
		{
			F_喝酒();
		}
	}

	public override void F_喝酒()
	{
		if (_Mono._Curr酒 > 0)
		{
			_Mono.ChangeState(StateType_Player.喝酒);
		}
	}

	public override void F_棍花Down()
	{
		_Mono.ChangeState(StateType_Player.棍花);
	}

	public override void F_棍花Up()
	{
	}

	public override void F_跳跃()
	{
		_Mono.ChangeState(StateType_Player.跳跃);
	}

	public override void F_轻攻击()
	{
		_Mono.ChangeState(StateType_Player.轻棍2);
	}

	public override void F_重攻击Down()
	{
		_Mono.ChangeState(StateType_Player.蓄力);
	}

	public override void F_重攻击Up()
	{
	}

	public override void F_翻滚()
	{
		_Mono.ChangeState(StateType_Player.翻滚);
	}

	public override void F_定身术()
	{
		if (_Mono._isOk_定身术)
		{
			Collider2D[] array = Physics2D.OverlapBoxAll(_Mono.transform.position, new Vector2(30f, 12f), 0f, LayerMask.GetMask("Enemy"));
			if (array.Length != 0)
			{
				Vector2 a = _Mono.transform.position;
				Collider2D collider2D = array[0];
				float num = Vector2.Distance(a, collider2D.transform.position);
				for (int i = 1; i < array.Length; i++)
				{
					float num2 = Vector2.Distance(a, array[i].transform.position);
					if (num2 < num)
					{
						num = num2;
						collider2D = array[i];
					}
				}
				_Mono._定身目标 = collider2D.GetComponentInParent<I定身术>();
				_Mono.ChangeState(StateType_Player.定身术);
			}
			else
			{
				Debug.LogError("范围内无目标");
			}
		}
		else
		{
			Debug.LogError("定身术在冷却");
		}
	}
}
